<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class kategori extends INSP_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->model('ctrlpnl/model_admin');
	}
	
	function index() {
		if ($this->session->userdata('logged_in') == TRUE) {
			$data['base_url'] = base_url();	
			$data['module']	 = 'kategori-admin';
			$this->load->view('ctrlpnl/vmain',$data);
		} else {
			$baseUrl = base_url();
			redirect($baseUrl.'ctrlpnl');
		}
	}
	
	function dataKategori(){
		echo $this->model_admin->getData('tb_category');
	}

	function formdata($param=""){
		$data['editstatus'] 	= $param;
		$data['base_url'] = base_url();	
		if($param == "new"){
			$this->load->helper('string');
			$code_category = random_string('alnum',5);
			$data['stateid'] 		= "";
			$data['category_code'] 	= strtoupper($code_category);
			$data['category_name'] 	= "";
		}elseif($param == "edit"){
			$id = $this->input->post('ID');
			$baseurl = base_url();
			$query = $this->model_admin->getRecord('tb_category', 'stateid', $id);
			
			$data['stateid'] 		= $query->stateid;
			$data['category_code'] 	= $query->category_code;
			$data['category_name'] 	= $query->category_name;
			
		}
		
		$this->load->view('ctrlpnl/kategori-admin/form-kategori', $data);
	}
	
	function saveData($param=""){
		$post = array();
		foreach($_POST as $k=>$v) $post[$k] = $this->input->post($k);
				
		echo $this->model_admin->saveDataModel($post,'tb_category',$param);

	}
	
	function deleteData(){
		$id = $this->input->post('ID');
		//$folder = "artikel";
		echo $this->model_admin->deleteDataModel('tb_category', $id, "");
	}


}